package com.usian.wemedia.wemedia.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usian.apis.service.wemedia.WeMediaController;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.common.enums.AppHttpCodeEnum;
import com.usian.model.media.pojos.WmUser;
import com.usian.wemedia.wemedia.service.MediaService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/wemedia/api")
public class MediaController implements WeMediaController {

    @Autowired
    private MediaService mediaService;

    @RequestMapping("/findByName/{name}")
    @Override
    public WmUser findByName(@PathVariable String name) {
        if(name!=null && !StringUtils.isEmpty(name)){
            WmUser one = mediaService.getOne(Wrappers.<WmUser>lambdaQuery().eq(WmUser::getName, name));
            return one;
        }
        return null;
    }

    @RequestMapping("/save")
    @Override
    public ResponseResult add(@RequestBody WmUser wmUser) {
        mediaService.save(wmUser);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }
}
